home *** CD-ROM | disk | FTP | other *** search
/ com!online 2005 May / com_0505_1.iso / opensource / top10 / amc_install.exe / {app} / Scripts / Amazon.fr.ifs < prev    next >
Encoding:
Text File  |  2004-03-20  |  6.7 KB  |  215 lines

  1. // GETINFO SCRIPTING
  2. // Amazon.fr (image uniquement)
  3.  
  4. (***************************************************
  5.  *  Script d'importation pour :                    *
  6.  *  AMAZON FRANCE , http://www.amazon.fr           *
  7.  *                                                 *
  8.  *  Script by DaJoss based on the scripts of       *
  9.  *  2003-12-25 : correction by antp                *
  10.  *                                                 *
  11.  *  A utiliser avec Ant Movie Catalog 3.4.2        *
  12.  *  www.antp.be/software/moviecatalog              *
  13.  *                                                 *
  14.  *  This program is free software; you can         *
  15.  *  redistribute it and/or modify it under the     *
  16.  *  terms of the GNU General Public License as     *
  17.  *  published by the Free Software Foundation;     *
  18.  *  either version 2 of the License, or (at your   *
  19.  *  option) any later version.                     *
  20.  ***************************************************)
  21.  
  22. program AMAZON_FR;
  23.  
  24. //ParamΦtres du script
  25. const
  26.  
  27.   // Mettre les valeurs α True pour importer les champs, ou False pour ne pas en tenir compte
  28.   ConfirmTitre = True;        // False : ne demande pas de confirmation du titre avant recherche
  29.   TempsPause = 500;        // 1000 = 1 Seconde (permet d'Θviter les timeout en cas de saturation serveur)
  30.   ImportImage = True;        // False : n'importe pas d'image
  31.     ImportGrandeImage = True;     // False : petite image importΘe
  32.   ImportBonus = True;        // False : n'importe pas les bonus dans la case Remarques
  33.   ImportTitreOriginal = False;    // False : n'importe pas le titre original
  34.  
  35.  
  36.  
  37. var
  38.   MovieName: string;
  39.  
  40. function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer;
  41. var
  42.   i: Integer;
  43. begin
  44.   result := -1;
  45.   if StartAt < 0 then
  46.     StartAt := 0;
  47.   for i := StartAt to List.Count-1 do
  48.     if Pos(Pattern, List.GetString(i)) <> 0 then
  49.     begin
  50.       result := i;
  51.       Break;
  52.     end;
  53. end;
  54.  
  55. procedure AnalyzePage(Address: string);
  56. var
  57.   Page: TStringList;
  58.   LineNr: Integer;
  59.  
  60. begin
  61.   Sleep(TempsPause); // Attente X seconde : Evite les timeout sur le serveur
  62.   Page := TStringList.Create;
  63.   Page.Text := GetPage(Address);
  64.   if pos('Sur ce DVD', Page.Text) > 0 then
  65.   begin
  66.     AnalyzeMoviePage(Page)
  67.   end else
  68.  
  69.   if pos('satisfaisante pour votre recherche sur', Page.Text) > 0 then
  70.   begin
  71.     ShowMessage('Aucun Film TrouvΘ pour : ' + MovieName);
  72.   end else
  73.  
  74.   if pos('Les articles les plus recherchés correspondant à', Page.Text) > 0 then
  75.   begin
  76.     PickTreeClear;
  77.     LineNr := 0;
  78.     LineNr := FindLine('résultats au total pour', Page, LineNr);
  79.     if LineNr > -1 then
  80.     begin
  81.       //PickTreeAdd('Films TrouvΘs :', '');
  82.       PickTreeAdd('Films TrouvΘs pour ' + MovieName + ' :', '');
  83.       AddMoviesTitles(Page, LineNr);
  84.     end;
  85.     if PickTreeExec(Address) then
  86.       AnalyzePage(Address);
  87.   end else
  88.  
  89.   begin
  90.     PickTreeClear;
  91.     LineNr := 0;
  92.     LineNr := FindLine('résultats au total pour', Page, LineNr);
  93.     if LineNr > -1 then
  94.     begin
  95.       //PickTreeAdd('Films TrouvΘs :', '');
  96.       PickTreeAdd('Films TrouvΘs pour ' + MovieName + ' :', '');
  97.       AddMoviesTitles(Page, LineNr);
  98.     end;
  99.     if PickTreeExec(Address) then
  100.       AnalyzePage(Address);
  101.   end;
  102.  
  103.   Page.Free;
  104. end;
  105.  
  106. procedure AnalyzeMoviePage(Page: TStringList);
  107. var
  108.   Line, Value, Value2, FullValue: string;
  109.   LineNr: Integer;
  110.   BeginPos, EndPos: Integer;
  111.  
  112. begin
  113.  
  114.   // Image
  115.   if ImportImage then
  116.   begin
  117.     LineNr := FindLine('<a href="http://images-eu.amazon.com/images/P/', Page, 0);
  118.     if LineNr > -1 then
  119.     begin
  120.       Line := Page.GetString(LineNr);
  121.       BeginPos := pos('src="', Line) + 4;
  122.       Delete(Line, 1, BeginPos);
  123.       EndPos := pos('"', Line);
  124.       Value := copy(Line, 1, EndPos - 1);
  125.       if ImportGrandeImage then
  126.         Value := StringReplace(Value, 'MZZZZZZZ', 'LZZZZZZZ'); // Change l'URL pour prendre la grande au lieu de la petite image
  127.       Sleep(TempsPause*3); // Attente 2X seconde : Evite les timeout sur le serveur
  128.       GetPicture(Value, False); // False = stocke l'image dans la base
  129.     end;
  130.   end;
  131.  
  132.    // Titre Original
  133.   if ImportTitreOriginal then
  134.     begin
  135.     LineNr := FindLine('Titre Original : ', Page, 0);
  136.     if LineNr > -1 then
  137.     begin
  138.       Line := Page.GetString(LineNr);
  139.       BeginPos := pos('Titre Original : ', Line)+27;
  140.       EndPos := pos('<br>', Line);
  141.       Value := copy(Line, BeginPos, EndPos - BeginPos);
  142.       SetField(fieldOriginalTitle, Value);
  143.     end;
  144.   end;
  145.  
  146.   // Bonus
  147.   if ImportBonus then
  148.   begin
  149.     LineNr := FindLine('<br><b>Bonus :</b><br>', Page, 0);
  150.     if LineNr > -1 then
  151.     begin
  152.       LineNr := LineNr + 1;
  153.       Line := Page.GetString(LineNr);
  154.       EndPos := Pos('<BR>', Line);
  155.       if EndPos > 0 then
  156.         Delete(Line, EndPos, Length(Line));
  157.       Value := 'Bonus :' + #13#10 + StringReplace(StringReplace(Line, '<br>', #13#10), '•', '-');
  158.       HTMLDecode(Value);
  159.       SetField(fieldComments, Value);
  160.     end;
  161.   end;
  162.  
  163.   DisplayResults;
  164. end;
  165.  
  166. procedure AddMoviesTitles(Page: TStringList; var LineNr: Integer);
  167. var
  168.   Line: string;
  169.   MovieTitle, MovieAddress: string;
  170.   StartPos: Integer;
  171.   StartImg: Integer;
  172.   StartLst: Integer;
  173.   LastLine: Integer;
  174.  
  175. begin
  176.   repeat
  177.     LineNr := LineNr + 1;
  178.     Line := Page.GetString(LineNr);
  179.     LastLine := Page.count;
  180.     StartPos := pos('<a href=/exec/obidos/ASIN/', Line);
  181.     StartImg := pos('<img src="http://images-eu.amazon.com/images/', Line);
  182.     StartLst := pos('</a>', Line);
  183.     if StartPos+StartImg+StartLst < StartPos+StartPos+StartPos-StartImg-StartLst then
  184.     begin
  185.       Startpos := Startpos + 9;
  186.       MovieAddress := copy(Line, StartPos, pos('qid', Line) - StartPos);
  187.       StartPos := pos('<b>', Line) + 3;
  188.       MovieTitle := copy(Line, StartPos, (StartPos + 150)- StartPos); 
  189.       HTMLDecode(Movietitle);
  190.       PickTreeAdd(MovieTitle, 'http://www.amazon.fr/' + MovieAddress);
  191.     end;
  192.   until (LineNr > Lastline);
  193. end;
  194.  
  195. begin
  196.   if CheckVersion(3,4,0) then
  197.   begin
  198.     MovieName := GetField(fieldTranslatedTitle);
  199.     if MovieName = '' then
  200.       MovieName := GetField(fieldOriginalTitle);
  201.  
  202.   if ConfirmTitre then
  203.     begin
  204.      if Input('Amazon.fr Import', 'Entrer le titre du film :', MovieName) then
  205.       begin
  206.        AnalyzePage('http://www.amazon.fr/exec/obidos/search-handle-url/index=dvd-fr&field-title='+UrlEncode(MovieName));
  207.       end;
  208.      end else
  209.       begin
  210.        AnalyzePage('http://www.amazon.fr/exec/obidos/search-handle-url/index=dvd-fr&field-title='+UrlEncode(MovieName));     
  211.       end;
  212.   end else
  213.    ShowMessage('Ce script requiert une version plus rΘcente de Ant Movie Catalog (au moins la version 3.4.0)');
  214. end.
  215.